﻿// <copyright file="LinqExtensions.cs" company="DataAbstractor">
//   (c) Luke Geraghty 2013
// </copyright>
// <summary>
//   Linq bindings.
// </summary>

namespace DataAbstractor
{
    /// <summary>
    /// Linq bindings.
    /// </summary>
    public static class LinqExtensions
    {
        /// <summary>
        /// Copy destination to source including any sub classes.
        /// </summary>
        /// <typeparam name="TDestination">The destination type.</typeparam>
        /// <param name="destination">The destination object.</param>
        /// <param name="source">The source object.</param>
        /// <returns>The destination class.</returns>
        public static TDestination DeepCopyFrom<TDestination>(this TDestination destination, object source)
        {
            DataAbstractor.Copy(destination, source, true);
            return destination;
        }

        /// <summary>
        /// Copy destination to source without any sub classes.
        /// </summary>
        /// <typeparam name="TDestination">The destination type.</typeparam>
        /// <param name="destination">The destination object.</param>
        /// <param name="source">The source object.</param>
        /// <returns>The destination class.</returns>
        public static TDestination ShallowCopyFrom<TDestination>(this TDestination destination, object source)
        {
            DataAbstractor.Copy(destination, source, false);
            return destination;
        }

        /// <summary>
        /// Create a new instance of destination and copy all properties from source in to destination.
        /// </summary>
        /// <typeparam name="TDestination">The destination type.</typeparam>
        /// <param name="source">The source value.</param>
        /// <returns>The destination with data copied from source.</returns>
        public static TDestination To<TDestination>(this object source) where TDestination : class, new()
        {
            return (TDestination)DataAbstractor.To(typeof(TDestination), source, true);
        }
    }
}
